package com.xin.springboot.component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Readpython {
    public static void readpython(String filepath) {
        try {
            String exe = "python";
            String command = filepath;
            String[] cmdArr = new String[]{exe, command};
            Process process = Runtime.getRuntime().exec(cmdArr);
            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            int result = process.waitFor();
            System.out.println("执行结果:" + result);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
